<?php
use Workerman\Worker;
require_once __DIR__ . '/../vendor/autoload.php';

$stunServer = new Worker('udp://0.0.0.0:3479');
$stunServer->onMessage = function ($connection, $data) {
    $clientPublicIp = $connection->getRemoteIp();
    $clientPublicPort = $connection->getRemotePort();
    // 返回客户端公网地址信息（RFC 5389简化实现）
    $response = pack('nnNn', 0x0101, 0x0000, ip2long($clientPublicIp), $clientPublicPort);
    $connection->send($response);
};

Worker::runAll();